package com.swpu.zdl.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swpu.zdl.pojo.JieYue;
import com.swpu.zdl.pojo.User;
import com.swpu.zdl.service.JieYueService;
import com.swpu.zdl.service.UserService;
import com.swpu.zdl.utils.Result;
import org.aspectj.lang.annotation.RequiredTypes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
@RequestMapping("/jieyue")
@CrossOrigin
public class JieYueController {
    @Autowired
    private JieYueService jieYueService;
    @GetMapping("/get")
    public Result GetJieYue(Integer current, Integer size,
                            @RequestParam(required = false) String jieYueName,
                            @RequestParam(required = false) String bookName){
        Page<JieYue> page = new Page<>(current, size);
        System.out.println(size);
        LambdaQueryWrapper<JieYue> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (jieYueName != null){
            lambdaQueryWrapper.like(JieYue::getUsername, jieYueName);
        }
        if (bookName != null){
            lambdaQueryWrapper.like(JieYue::getBookName, bookName);
        }
        Page<JieYue> page1 = jieYueService.page(page, lambdaQueryWrapper);
        return new Result(200, "借阅信息", page1);
    }
    @PutMapping("/jieyue")
    public Result SetJieYue(@RequestBody JieYue jieYue){
        jieYueService.SetJieYue(jieYue);
        return new Result(200, "借阅成功", jieYue);
    }
    @PutMapping("/guihuan")
    public Result GuiHuan(@RequestBody JieYue jieYue){
        jieYueService.GuiHuan(jieYue);
        return new Result(200, "归还书籍", jieYue);
    }
}
